
async function begin() {
   try {
    await sleep(5000); // 使用异步 sleep 函数
    var video = document.getElementById("html5player_html5_api");
    if(video)
    {
      
    } else{
      video  = document.getElementById("video-root").shadowRoot.getElementById('html5player_html5_api');
    }
    
    video.addEventListener('click', function(event) {
      if(document.fullscreenElement){
        if (video.paused) {
          video.play();
        } else {
          video.pause();
        }
      }
      
    });
    // 添加按键监听事件
    document.addEventListener('keydown', function(event) {
      // 检查是否按下 F 键
      if (event.key.toLowerCase() === 'f') {
        // 切换全屏模式
        console.log('fullscreen')
        if (!document.fullscreenElement) {
          fullScreen(video);
        } else {
          if (document.exitFullscreen) {
            document.exitFullscreen();
          }
        }
        
      }
      else if (event.keyCode == 32)
      {
        if(document.fullscreenElement)
        {
          console.log("space ...")
          console.log(video)
          if (video.paused) {
            video.play();
          } else {
            video.pause();
          }
        }
        
      }
    });
    // 全屏
    function fullScreen(video){
      if(video.mozRequestFullScreen){
          video.mozRequestFullScreen();//火狐浏览器
      }else if(video.webkitRequestFullscreen){
          video.webkitRequestFullscreen();//谷歌浏览器
      }else if(video.oRequestFullscreen){
          video.oRequestFullscreen(); //opera浏览器
      }else if(video.msRequestFullscreen){
          video.msRequestFullscreen();  //ie浏览器
      }else if(video.requestFullscreen){
          video.requestFullscreen();
      }
    }
   } catch (error) {
     console.error("出现错误:", error);
   }
 }
 
 async function sleep(ms) {
   return new Promise(resolve => setTimeout(resolve, ms));
 }
begin();